{extend name="layout"/}
{block name="button"}
{if authCheck('role/roleadd')}
&nbsp;<button type="button" onclick="add()" class="btn btn-mystyle btn-sm">添加角色</button>
{/if}
{/block}
{block name="content"}
<div class="table-margin">
    <table class="table table-bordered table-header" id="list-table">
        <thead>
        <tr>
            <td>角色名称</td>
            <td>绑定管理员</td>
            <td>状态</td>
            <td class="w20">操作</td>
        </tr>
        </thead>
        <tbody>
            {foreach name="roles" item="vo"}
            <tr>
                <td>{$vo['role_name']}</td>
                <td>{$vo['num']}人</td>
                <td>
                    <img width="20" height="20" src="__IMG__/{$Think.config.role_status[$vo.status]}"/>
                </td>
                <td>{$key==0?'':$vo['operate']}</td>
            </tr>
            {/foreach}
        </tbody>
    </table>
</div>

<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title"> 添加角色</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="{:url('Role/roleAdd')}" method="post">
                    <table class="table table-bordered contact-template-form">
                        <tbody><tr>
                            <td width="20%" align="right">角色名称：</td>
                            <td>
                                <input class="form-control" type="text" name="role_name" required="" aria-required="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <input class="btn btn-primary" type="submit" value="添加">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title"> 修改角色</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="{:url('Role/roleEdit')}" method="post">
                    <input type="hidden" name="id">
                    <table class="table table-bordered contact-template-form">
                        <tbody>
                        <tr>
                            <td width="20%" align="right">角色名称：</td>
                            <td>
                                <input class="form-control" type="text" name="role_name" required="" aria-required="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="right">状态：</td>
                            <td class="mystatus">
                                <label><input class="xb-icheck" type="radio" name="status" value="0"><span class="pull-right">&nbsp;启用&nbsp;&nbsp;&nbsp;&nbsp;</span></label>
                                <label><input class="xb-icheck" type="radio" name="status" value="1"><span class="pull-right">&nbsp;禁用&nbsp;&nbsp;&nbsp;&nbsp;</span></label>
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-primary" type="submit" value="修改">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var role_del_url = "{:url('role/roleDel')}";
    function add(){
        $('#bjy-add').modal('show');
    }
    function edit(id,title,status){
        $("input[name='id']").val(id);
        $("#bjy-edit input[name='role_name']").val(title);
        if(status == 0){
            $("input[name='status']").get(0).checked = true;
        }else{
            $("input[name='status']").get(1).checked = true;
        }
        $('#bjy-edit').modal('show');
    }
    function delRole(id,num){
        if(num > 0){
            layer.alert('该角色下有绑定会员，不可删除!', {icon:2, title:'失败提示', closeBtn:0, anim:6});
            return false;
        }
        //询问框
        var index = layer.confirm('确定要删除该角色吗？', {
            icon: 3,
            title: '友情提示',
            btn: ['确定','取消'] //按钮
        }, function(){
            $.getJSON(role_del_url, {id : id},function(res){
                layer.close(useradd);
                if(1 == res.code){
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {icon:2});
                }
            });
        }, function(){});
    }

    $(function () {
        $('#bjy-add form').submit(function(){
            $(this).ajaxSubmit({
                success:showSuccess
            });
            return false;
        });
        // 编辑节点
        $('#bjy-edit form').submit(function(){
            $(this).ajaxSubmit({
                success:showSuccess
            });
            return false;
        });
    });
</script>
{/block}